<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='main'){
	exi($return);
}
/*******op*******/
set_html('title','牵线任务');
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id']);
	$params['status']=intval($_RQ['status']);
	$return['status']=intval($_RQ['status']);
	if($_RQ['today']){
		$params['createtime >']=strtotime(date('ymd'));
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$worker_log=pdo_getslice('jy_ailiao_worker_log',$params,array($pindex,$psize),$total,array(),'','createtime desc');
	if($worker_log){
		$current_year=date('Y');
		$zhiweis=$this->model('model')->zhiweis();
		foreach($worker_log as $k=>&$item){
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$member=$this->model('member')->get_member($item['mid']);
			$member['nickname']=$member['nickname']?:$return['item']['nickname'];
			$member['avatar']=$member['avatar']?:$return['item']['avatar'];
			$member['images']=json_decode($member['images'],true);
			$member['birth']=json_decode($member['birth'],true);
			foreach($member['images'] as &$img){
				$img=tomedia($img);
			}
			$member['avatar']=$member['avatar']?:$item['images'][0];
			$member['sextitle']=$this->sex[$member['sex']];
			$member['picsnum']=count($member['images']);
			$member['age'] = $member['birth']['year']?$current_year - $member['birth']['year'] - 1:'**';
			$member['height']=$this->heights[$member['height']];
			$member['zhiwei']=$zhiweis[$member['zhiwei']];
			$item['member']=$member;
			$tomember=$this->model('member')->get_member($item['tomid']);
			$tomember['nickname']=$tomember['nickname']?:$return['item']['nickname'];
			$tomember['avatar']=$tomember['avatar']?:$return['item']['avatar'];
			$tomember['images']=json_decode($tomember['images'],true);
			$tomember['birth']=json_decode($tomember['birth'],true);
			foreach($tomember['images'] as &$img){
				$img=tomedia($img);
			}
			$tomember['avatar']=$tomember['avatar']?:$item['images'][0];
			$tomember['sextitle']=$this->sex[$tomember['sex']];
			$tomember['picsnum']=count($tomember['images']);
			$tomember['age'] = $tomember['birth']['year']?$current_year - $tomember['birth']['year'] - 1:'**';
			$tomember['height']=$this->heights[$tomember['height']];
			$tomember['zhiwei']=$zhiweis[$tomember['zhiwei']];
			$item['tomember']=$tomember;
			$item['statustitle']=$this->workerlog_status[$item['status']];
		}
	}
	$return['list']=$worker_log;
	$workers=pdo_getall('jy_ailiao_worker',array('uniacid'=>$_SESSION['uniacid']),'','id');
	$workers[0]=array('id'=>0,'title'=>'无红娘');
	$return['isopenvoice']=$this->session('isopenvoice')?1:0;
	$return['workers']=$workers;
	exi($return);
}
//员工确认任务
if($_RQ['op']=='status2'){
	$order_id=intval($_RQ['id']);
	if(!$order_id){
		exi('任务不存在，请重新选择任务','error');
	}
	$this->model('worker')->logstatus2($order_id);
	exi('恭喜你完成牵线！感谢你的努力！');
}
//员工确认接单
if($_RQ['op']=='status1'){
	$order_id=intval($_RQ['id']);
	if(!$order_id){
		exi('任务不存在，请重新选择任务','error');
	}
	$this->model('worker')->logstatus1($order_id);
	exi('确认成功！');
}
//报备
if($_RQ['op']=='baobei'){
	$post=get_postdata();
	$order_id=intval($post['id']);
	if(!$order_id){
		exi('任务不存在，请重新选择任务','error');
	}
	$order=pdo_update('jy_ailiao_worker_log',array('status'=>7,'remark'=>$post['remark']),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
	exi('报备成功！','','jy_ailiao/worker.worder/list/');
}